let dataMgr = require("./DataMgr");
cc.Class({
    extends: cc.Component,

    properties: {
        curScoreLabel: cc.Label,
        maxScoreLabel: cc.Label,
    },

    onLoad() {
        this.curScore = 0;
        this.maxScore = cc.sys.localStorage.getItem("RunCool_MaxScore");
        if (this.maxScore == undefined) {
            this.maxScore = 0;
        }
        dataMgr.getInstance().saveData("curScore", this.curScore);
        dataMgr.getInstance().saveData("maxScore", this.maxScore);
        this.curScoreLabel.string = `当前得分：${this.curScore}分`;
        this.maxScoreLabel.string = `最高得分：${this.maxScore}分`;
    },

    start() {

    },

    update(dt) {

    },
    updateScore(score) {
        this.curScore += score;
        this.curScoreLabel.string = `当前得分：${this.curScore}分`;
        dataMgr.getInstance().saveData("curScore", this.curScore);
        if (this.curScore > this.maxScore) {
            this.maxScore = this.curScore;
            cc.sys.localStorage.setItem("RunCool_MaxScore", this.maxScore);
            this.maxScoreLabel.string = `最高得分：${this.maxScore}分`;
            dataMgr.getInstance().saveData("maxScore", this.maxScore);
        }
    },

});
